package com.example.androidautoproject.utils

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import java.util.ArrayList

object AdParam {
    var isStart:Boolean = false
    var className:String = ""
    var packageName:String = ""
    var className1:String = ""
    var packageName1:String = ""
    var adLog:MutableList<String> = mutableListOf()
    var currentTag = ""
    var screenPackageName:String = ""
    var ip:String = ""

    // 观察者列表
    private val observers = mutableListOf<(String) -> Unit>()

    // 添加日志并通知观察者
    fun addLog(message: String) {
        adLog.add("${System.currentTimeMillis()}: $message")
        notifyObservers(message)
    }

    // 注册观察者
    fun registerObserver(observer: (String) -> Unit) {
        observers.add(observer)
    }

    // 取消注册观察者
    fun unregisterObserver(observer: (String) -> Unit) {
        observers.remove(observer)
    }

    // 通知所有观察者
    private fun notifyObservers(message: String) {
        observers.forEach { it.invoke(message) }
    }

    // 清空日志
    fun clearLog() {
        adLog.clear()
    }

    // 获取所有日志
    fun getAllLogs(): String {
        return adLog.joinToString("\n")
    }
}